% Brief Introduction:
% This function calculates the polynomial coefficients of a given order 
% derivative for a given polynomial specified by the input polynomial 
% coefficients.
% Usage:
%   DerPCoef    =   PCoefDer(PCoef,order)
% Inputs:
%   PCoef       :   The Polynomial representation coefficient matrix, 
%                   its dimension is (#breaks-1) x (k+1)
%   order       :   Order of derivative
% OUTPUTS
%   DerPCoef    :   Spline polynomial coefficients of the derivative
%                   polynomial
%
% Author:       Xing Guo, University of Michigan, xingguo@umich.edu
% Version:      Nov 28, 2017               
% USES: 

function DerPCoef=PCoefDer(PCoef,order)

k           =   size(PCoef,2)-1;
if order<0
    error('Derivative order cannot be negative');
elseif order>k
    error('Derivative order cannot exceed the polynomial order');
end 

DerPCoef    =   PCoef(:,(1:1:k+1-order));
Multiplier  =   factorial((k:-1:order))./factorial((k-order:-1:0));
DerPCoef    =   bsxfun(@times,DerPCoef,Multiplier);
